<template>
<div>
 <van-nav-bar
    title="登录"
    left-text=""
   
    left-arrow
    @click-left="onClickLeft"
  
  />
  <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    label=""
    placeholder="手机号/账户名/邮箱"
    :rules="[{ required: true, message: '' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    label=""
    placeholder="请输入密码"
    :rules="[{ required: true, message: '' }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">登录</van-button>
    <p><router-link to="/zhuce" class="p">没有账号，我要注册</router-link></p>
  </div>
 
</van-form>
</div>

 
</template>



<script>
import {login} from "../api/link"
import { Toast } from 'vant';
import { Dialog } from 'vant';
export default {
  data() {
    return {
      username: '',
      password: '',
    };
  },
  methods: {
    onClickLeft() {
      
      this.$router.push('/home')
    },
    onClickRight() {
      Toast('按钮');
    },
     onSubmit(values) {
      console.log('submit', values);
      login(values.loginname,values.password).then((ok)=>{
        console.log(ok)
        alert(ok.data.message)
      if (ok.data.code == 200) {
          Dialog.alert({
            title: "登录",
            message: "恭喜你登录成功!!",
          }).then(() => {
            // on close
            this.$router.push('/home')
          });
        }
      })
    },
  },
};
</script>

<style>
</style>